package com.boco.pciv.controller.sys;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.boco.pciv.controller.PcivController;
import com.boco.pciv.core.entity.LayUIPager;
import com.boco.pciv.core.entity.PageResultBase;
import com.boco.pciv.core.entity.SearchCriteria;
import com.boco.pciv.service.sys.IUserLogService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(value="/sys/log")
public class LogController extends PcivController {
	@Resource
	private IUserLogService srv;

	@GetMapping("/list")
	public String getList(Integer logType, String userIP, String userId, String startTime, String endTime, String module, LayUIPager pageParam){
		SearchCriteria param = new SearchCriteria();
		param.setPager(pageParam);
		if(logType!=null) {
			param.putCriteria("logType", logType);
		}
		if(StrUtil.isNotBlank(userId)){
			param.putCriteria("userId", userId);
		}
		if(StrUtil.isNotBlank(startTime)){
			param.putCriteria("startTime", DateUtil.parse(startTime,"yyyy-MM-dd HH:mm:ss"));
		}
		if(StrUtil.isNotBlank(endTime)){
			param.putCriteria("endTime", DateUtil.parse(endTime, "yyyy-MM-dd HH:mm:ss"));
		}
		if(StrUtil.isNotBlank(userIP)){
			param.putCriteria("userIP", userIP);
		}
		if(StrUtil.isNotBlank(module)){
			param.putCriteria("module", module);
		}
		PageResultBase result=srv.getPage(param);
		return JSONUtil.toJsonStr(result);
	}
}
